package com.cqie.secondhandtransaction.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

import com.cqie.secondhandtransaction.DTO.AccessUserDTO;
import com.cqie.secondhandtransaction.enums.RoleEnum;
import com.cqie.secondhandtransaction.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *
 * </p>
 *
 * @author gdy
 * @since 2025-02-10
 */
@Getter
@Setter
@TableName("user_info")
@ApiModel(value = "UserInfo对象", description = "")
public class UserInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("姓名")
    private String userName;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("电话号码，11位")
    private String phone;

    @ApiModelProperty("角色，0-管理员，1-买家，2-卖家")
    private Integer role;

    @ApiModelProperty("地址")
    private String address;

    @ApiModelProperty("售卖件数")
    @TableField(fill = FieldFill.INSERT)
    private Integer soldNum;

    @ApiModelProperty("头像")
    private String picture;

    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date createTime;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date updateTime;

    @ApiModelProperty("删除标识")
    @TableLogic
    private Integer isDelete;

    //设置角色
    public void buildRole() {
        this.role = RoleEnum.USER.getRole();
    }

    //构建商品评价的用户信息
    public AccessUserDTO buildAccessUserInfo() {
        AccessUserDTO accessUserDTO = new AccessUserDTO();
        BeanUtils.copyProperties(this, accessUserDTO);
        accessUserDTO.setSellerAvatar(this.picture);
        return accessUserDTO;
    }

}
